/**
 *  *2010-7-19 下午03:44:57  add 
 */
package com.base.myproject.client.HR.bcode;

import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * 更新信息到工作记录
 * @author Administrator
 *2010-7-19
 * javazgw@gmail.com
 */
public class UpdateDialog {
	
	
	public UpdateDialog(final String updatesql)
	{
		MessageBox.confirm("提示", "是否更新此数据到工作记录",new Listener<MessageBoxEvent>(){

			@Override
			public void handleEvent(MessageBoxEvent be) {
				 Button btn = be.getButtonClicked();  
				 
				 
				 if(btn.equals(be.getDialog().getButtonById(Dialog.YES)))
				 {
					 GWT.log("ok");
					 CommandSyncsql csql = new CommandSyncsql();
					 csql.getV().add(updatesql);
					 GreetingServiceAsync greetingService = GWT
						.create(GreetingService.class);
					 
					 CommandSyncContainer list = new CommandSyncContainer();
					 list.add(csql);
					 greetingService
						.SendCommandSync(
								list,
								new AsyncCallback<CommandSyncReturnObject>() {
									@Override
									public void onFailure(
											Throwable caught) {
										MessageBox.alert("错误",
												"网络连接失败", null);
										
									}
									@Override
									public void onSuccess(
											CommandSyncReturnObject result) {
										if (result.isB()) {
											Info.display("", "更新成功");
											ok();
										}
										else{
											MessageBox.alert("错误",
													"错误，错误代码"+result.getMessage(), null);
											
										}
									}
								});
					
				 }
				 else if(btn.equals(be.getDialog().getButtonById(Dialog.NO)))
				 {
					 GWT.log("CANCEL");
				 }
				 
				
				
			}
			
		});
	}
	
	protected void ok()
	{
		
	}

}
